<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     base_default
 */
?>

<?php
/**
 * Template for displaying bundle product price in RSS feeds
 *
 * @see Mage_Bundle_Block_Catalog_Product_Price
 * @var Mage_Bundle_Block_Catalog_Product_Price $this 
 */
?>

<?php $_product = $this->getProduct() ?>
<?php [$_minimalPrice, $_maximalPrice] = $_product->getPriceModel()->getPrices($_product) ?>
<?php $_id = $_product->getId() ?>

<?php
/**
 * @var Mage_Core_Helper_Data $_coreHelper
 * @var Mage_Weee_Helper_Data $_weeeHelper
 * @var Mage_Tax_Helper_Data $_taxHelper
 */
$_coreHelper = $this->helper('core');
$_weeeHelper = $this->helper('weee');
$_taxHelper = $this->helper('tax');
$_weeeTaxAmount = 0; ?>

<?php $_minimalPriceTax = Mage::helper('tax')->getPrice($_product, $_minimalPrice); ?>
<?php $_minimalPriceInclTax = Mage::helper('tax')->getPrice($_product, $_minimalPrice, true); ?>

<?php
if ($_product->getPriceType() == 1) {
    $_weeeTaxAmount = $_weeeHelper->getAmountForDisplay($_product);
    $_weeeTaxAmountInclTaxes = $_weeeTaxAmount;

    if ($_weeeHelper->isTaxable()) {
        $_attributes = $_weeeHelper->getProductWeeeAttributesForRenderer($_product, null, null, null, true);
        $_weeeTaxAmountInclTaxes = $_weeeHelper->getAmountInclTaxes($_attributes);
    }

    if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($_product, [0, 1, 4])) {
        $_minimalPriceTax += $_weeeTaxAmount;
        $_minimalPriceInclTax += $_weeeTaxAmountInclTaxes;
    }
    if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($_product, 2)) {
        $_minimalPriceInclTax += $_weeeTaxAmountInclTaxes;
    }

    if (Mage::helper('weee')->typeOfDisplay($_product, [1, 2, 4])) {
        $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForRenderer($_product, null, null, null, true);
    }
}
?>

<div class="price-box">
<?php if ($_product->getPriceView()): ?>
    <p class="minimal-price">
        <span class="price-label"><?php echo $this->__('As low as') ?>:</span>
        <?php if ($this->helper('tax')->displayBothPrices()): ?>
            <span class="price-excluding-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Excl. Tax:') ?></span>
                <?php echo Mage::helper('core')->currency($_minimalPriceTax) ?>
                    </span>
            <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                <span class="weee">(<small>
                        <?php $_weeeSeparator = '';
                        foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                            <?php if (Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                            <?php else: ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                            <?php endif ?>

                            <?php echo $_weeeSeparator; ?>
                            <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                            <?php $_weeeSeparator = ' + '; ?>
                        <?php endforeach ?>
                    </small>)</span>
            <?php endif ?>
            <span class="price-including-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Incl. Tax:') ?></span>
                <?php echo Mage::helper('core')->currency($_minimalPriceInclTax) ?>
                    </span>
        <?php else: ?>
            <?php if ($_taxHelper->displayPriceIncludingTax()): ?>
                <?php echo $_coreHelper->currency($_minimalPriceInclTax) ?>
            <?php else: ?>
                <?php echo $_coreHelper->currency($_minimalPriceTax) ?>
            <?php endif ?>
            <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                <span class="weee">(<small>
                        <?php $_weeeSeparator = '';
                        foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                            <?php if (Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                            <?php else: ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                            <?php endif ?>

                            <?php echo $_weeeSeparator; ?>
                            <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                            <?php $_weeeSeparator = ' + '; ?>
                        <?php endforeach ?>
                    </small>)</span>
            <?php endif ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                <?php echo Mage::helper('core')->currency($_minimalPriceInclTax) ?>
            <?php endif ?>
        <?php endif ?>
    </p>
<?php else: ?>
    <?php if ($_minimalPrice != $_maximalPrice): ?>
        <p class="price-from">
            <span class="price-label"><?php echo $this->__('From') ?>:</span>
            <?php if ($this->helper('tax')->displayBothPrices()): ?>
                <span class="price-excluding-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Excl. Tax:') ?></span>
                    <?php echo Mage::helper('core')->currency($_minimalPriceTax) ?>
                    </span>
                <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                    <span class="weee">(<small>
                            <?php $_weeeSeparator = '';
                            foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if (Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?php echo $_weeeSeparator; ?>
                                <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                <?php endif ?>
                <span class="price-including-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Incl. Tax:') ?></span>
                    <?php echo Mage::helper('core')->currency($_minimalPriceInclTax) ?>
                    </span>
            <?php else: ?>
                <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                    <?php echo $_coreHelper->currency($_minimalPriceInclTax) ?>
                <?php else: ?>
                    <?php echo $_coreHelper->currency($_minimalPriceTax) ?>
                <?php endif ?>

                <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                    <span class="weee">(<small>
                            <?php $_weeeSeparator = '';
                            foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_taxHelper->displayPriceIncludingTax() || Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?php echo $_weeeSeparator; ?>
                                <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                <?php endif ?>
                <?php if (Mage::helper('weee')->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                    <?php echo Mage::helper('core')->currency($_minimalPriceInclTax) ?>
                <?php endif ?>
            <?php endif ?>
        </p>
        <?php $_maximalPriceTax = Mage::helper('tax')->getPrice($_product, $_maximalPrice); ?>
        <?php $_maximalPriceInclTax = Mage::helper('tax')->getPrice($_product, $_maximalPrice, true); ?>
        <?php
        if ($_product->getPriceType() == 1) {
            if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($_product, [0, 1, 4])) {
                $_maximalPriceTax += $_weeeTaxAmount;
                $_maximalPriceInclTax += $_weeeTaxAmountInclTaxes;
            }
            if ($_weeeTaxAmount && Mage::helper('weee')->typeOfDisplay($_product, 2)) {
                $_maximalPriceInclTax += $_weeeTaxAmountInclTaxes;
            }
        }
        ?>
        <p class="price-to">
            <span class="price-label"><?php echo $this->__('To') ?>:</span>
            <?php if ($this->helper('tax')->displayBothPrices()): ?>
                <span class="price-excluding-tax">
                            <span class="label"><?php echo Mage::helper('tax')->__('Excl. Tax:') ?></span>
                    <?php echo Mage::helper('core')->currency($_maximalPriceTax) ?>
                        </span>
                <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                    <span class="weee">(<small>
                            <?php $_weeeSeparator = '';
                            foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if (Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?php echo $_weeeSeparator; ?>
                                <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                <?php endif ?>
                <span class="price-including-tax">
                            <span class="label"><?php echo Mage::helper('tax')->__('Incl. Tax') ?></span>
                    <?php echo Mage::helper('core')->currency($_maximalPriceInclTax) ?>
                        </span>
            <?php else: ?>
                <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                    <?php echo $_coreHelper->currency($_maximalPriceInclTax) ?>
                <?php else: ?>
                    <?php echo $_coreHelper->currency($_maximalPriceTax) ?>
                <?php endif ?>

                <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                    <span class="weee">(<small>
                            <?php $_weeeSeparator = '';
                            foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                                <?php if ($_taxHelper->displayPriceIncludingTax() || Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                                <?php else: ?>
                                    <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                                <?php endif ?>

                                <?php echo $_weeeSeparator; ?>
                                <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                                <?php $_weeeSeparator = ' + '; ?>
                            <?php endforeach ?>
                        </small>)</span>
                <?php endif ?>
                <?php if (Mage::helper('weee')->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                    <?php echo Mage::helper('core')->currency($_maximalPriceInclTax) ?>
                <?php endif ?>
            <?php endif ?>
        </p>
    <?php else: ?>
        <?php if ($this->helper('tax')->displayBothPrices()): ?>
            <span class="price-excluding-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Excl. Tax:') ?></span>
                <?php echo Mage::helper('core')->currency($_minimalPriceTax) ?>
                    </span>
            <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                <span class="weee">(<small>
                        <?php $_weeeSeparator = '';
                        foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                            <?php if (Mage::helper('weee')->typeOfDisplay($_product, [2, 4])): ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                            <?php else: ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                            <?php endif ?>

                            <?php echo $_weeeSeparator; ?>
                            <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                            <?php $_weeeSeparator = ' + '; ?>
                        <?php endforeach ?>
                    </small>)</span>
            <?php endif ?>
            <span class="price-including-tax">
                        <span class="label"><?php echo Mage::helper('tax')->__('Incl. Tax:') ?></span>
                <?php echo Mage::helper('core')->currency($_minimalPriceInclTax) ?>
                    </span>
        <?php else: ?>
            <?php echo Mage::helper('core')->currency($_minimalPriceTax) ?>
            <?php if ($_weeeTaxAmount && $_product->getPriceType() == 1 && Mage::helper('weee')->typeOfDisplay($_product, [2, 1, 4])): ?>
                <span class="weee">(<small>
                        <?php $_weeeSeparator = '';
                        foreach ($_weeeTaxAttributes as $_weeeTaxAttribute): ?>
                            <?php if ($_taxHelper->displayPriceIncludingTax()): ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount(); ?>
                            <?php else: ?>
                                <?php $amount = $_weeeTaxAttribute->getAmount(); ?>
                            <?php endif ?>

                            <?php echo $_weeeSeparator; ?>
                            <?php echo $_weeeTaxAttribute->getName(); ?>: <?php echo Mage::helper('core')->currency($amount, true, true); ?>
                            <?php $_weeeSeparator = ' + '; ?>
                        <?php endforeach ?>
                    </small>)</span>
            <?php endif ?>
            <?php if (Mage::helper('weee')->typeOfDisplay($_product, 2) && $_weeeTaxAmount): ?>
                <?php if ($_taxHelper->displayPriceIncludingTax()) : ?>
                    <?php echo $_coreHelper->currency($_minimalPriceInclTax) ?>
                <?php else: ?>
                    <?php echo $_coreHelper->currency($_minimalPriceTax + $_weeeTaxAmount) ?>
                <?php endif ?>
            <?php endif ?>
        <?php endif ?>
    <?php endif ?>
<?php endif ?>
</div>
